home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / graphics / vlapak1.zip / MODINFO.ZIP / POLLPLAY.ASM < prev    next >
Assembly Source File  |  1993-04-16  |  5KB  |  235 lines

  1.       DOSSEG
  2.       .MODEL SMALL
  3.       .STACK 200h
  4.       .CODE
  5.       .386
  6.       ASSUME CS:@CODE, DS:@CODE
  7.       Ideal
  8.  
  9. ────────────────────────────────────────────────────────
  10.  
  11. OldInt  dd  ?
  12.  
  13. BaseAddress dw 220h
  14.  
  15. SampleSeg dw  ?
  16. SampleOff dw  0
  17.  
  18. FileName  db  "jamhot.sam",0   ;you need to put your filename here...
  19. SamLength dw  ?
  20.  
  21. ────────────────────────────────────────────────────────
  22.       
  23. PROC TurnOffSpeaker NEAR
  24.     mov     al,0d3h         ;turn off speaker
  25.     call    Sendcommand
  26.     ret
  27. ENDP TurnOffSpeaker
  28.  
  29.     ;al = command
  30. PROC SendCommand NEAR
  31.     push    dx
  32.     push    ax
  33.     mov     dx,[cs:BaseAddress]
  34.     add     dx,0ch
  35. sendcommandloop:
  36.     in      al,dx
  37.     or      al,al
  38.     js      sendcommandloop
  39.     pop     ax
  40.     out     dx,al
  41.     pop     dx
  42.     ret
  43. ENDP SendCommand
  44.  
  45. PROC TurnOnSpeaker NEAR
  46.     mov     al,0d1h
  47.     call    SendCommand
  48.     ret
  49. ENDP TurnOnSpeaker
  50.  
  51.     ;input- none 
  52.     ;output al=0 successful
  53.     ;       al=1 unsuccessful
  54.     ;Destroys AX,DX,CX
  55.     ;
  56. PROC DspReset NEAR
  57.     mov     dx,[cs:baseaddress]
  58.     add     dx,06h
  59.     mov     al,1
  60.     out     dx,al
  61.     mov     cx,1000
  62.     push    di
  63.     rep     lodsb         ;wait for at least 3µS
  64.     pop     di
  65.     xor     al,al
  66.     out     dx,al
  67.  
  68.     add     dx,8          ;check status (22eh)
  69.     mov     cx,12000
  70. waitforstat:
  71.     in      al,dx
  72.     dec     cx
  73.     je      errorstat
  74.     or      al,al
  75.     js      WaitForStat
  76.  
  77.     mov     cx,10000
  78.     sub     dx,4          ;(22ah)      
  79. waitforstat2:
  80.     in      al,dx
  81.     dec     cx
  82.     je      errorstat
  83.     cmp     al,0aah
  84.     jne     waitforstat2
  85.     mov     al,0
  86.     ret
  87. errorstat:
  88.     mov     al,1
  89.     ret
  90. ENDP DspReset
  91.  
  92. PROC SetUpInterrupt NEAR
  93.     pusha
  94.     push    ds
  95.  
  96.     mov   ax,0
  97.     mov   ds,ax
  98.     mov   bx,8*4                  ;interrupt 8
  99.     mov   ax,[ds:bx]
  100.     mov   [Word LOW  cs:OldInt],ax
  101.     mov   ax,[ds:bx+2]
  102.     mov   [Word HIGH cs:OldInt],ax
  103.  
  104.     cli
  105.     mov   [Word ds:bx],offset TimerInt
  106.     mov   [ds:bx+2],cs
  107.  
  108.     mov   al,36h
  109.     out   43h,al                  ; timer program
  110.  
  111.     mov   ax,1193180/8000         ; # of ticks between interrupts
  112.                                   ; Clock Freq / HZ
  113.     out   40h,al
  114.     mov   al,ah
  115.     out   40h,al
  116.     sti
  117.  
  118.     pop     ds
  119.     popa
  120.     ret
  121. ENDP SetUpInterrupt
  122.   
  123. PROC RemoveInterrupt NEAR
  124.     pusha
  125.     push    ds
  126.     
  127.     cli
  128.     mov ax,0
  129.     mov ds,ax
  130.     mov bx,8*4
  131.     mov ax,[Word cs:OldInt]
  132.     mov [ds:bx],ax
  133.     mov ax,[Word cs:OldInt+2]
  134.     mov [ds:bx+2],ax
  135.     mov al,36h
  136.     out 43h,al
  137.     xor al,al
  138.     out 40h,al
  139.     out 40h,al
  140.     sti
  141.     
  142.     pop     ds
  143.     popa
  144.     ret
  145. ENDP  RemoveInterrupt
  146.  
  147. PROC TimerInt FAR
  148.     pusha
  149.     push    fs
  150.     
  151.     mov     fs,[cs:SampleSeg]
  152.     mov     di,[cs:SampleOff]
  153.     
  154.     mov     al,10h + 0b            ;Direct 8-bit DAC command
  155.     call    SendCommand
  156.  
  157.     mov     al,[fs:di]
  158.     add     al,128            ;change SAM data (-128 to 127) to SB data 0-255
  159.     call    SendCommand
  160.     
  161.     inc     [cs:SampleOff]
  162.     mov     ax,[CS:SamLength]
  163.     cmp     [cs:SampleOff],ax
  164.     jb      @@NotOver
  165.     mov     [cs:SampleOff],0
  166.  
  167. @@NotOver:
  168.     mov     al,20h      ;acknowledge hardware interrupt
  169.     out     20h,al
  170.  
  171.     pop     fs
  172.     popa
  173.     iret
  174. ENDP TimerInt
  175.  
  176.   ; returns -1 if load not successful
  177. PROC  LoadSample NEAR
  178.     pusha
  179.  
  180.     mov     ax,cs
  181.     mov     ds,ax
  182.     mov     dx,offset FileName
  183.     mov     ax,3D00h        ;open the file
  184.     int     21h
  185.     jc      @@Error
  186.  
  187.     mov     bx,ax
  188.     xor     dx,dx             ;load at offset 0
  189.     mov     cx,0ffffh         ;read in a whole segments worth
  190.     mov     ds,[cs:SampleSeg]
  191.     mov     ax,3F00h          ; Load in the sample
  192.     int     21h
  193.  
  194.     mov     [cs:SamLength],ax
  195.  
  196.     mov     ax,3E00h          ;close the file
  197.     int     21h
  198.     
  199.     popa
  200.     xor     ax,ax
  201.     ret
  202.  
  203. @@Error:
  204.     popa
  205.     mov     ax,-1
  206.     ret
  207. ENDP  LoadSample
  208.  
  209. ────────────────────────────────────────────────────────────────────────────
  210.  
  211. START:
  212.     mov   bx,ss
  213.     add   bx,20h            ;put sample right after stack
  214.     mov   [cs:SampleSeg],bx
  215.  
  216.     call  LoadSample
  217.     or    al,al
  218.     jne   ByeBye
  219.  
  220.     call  DspReset
  221.     call  TurnOnSpeaker
  222.     call  SetUpInterrupt    ;starts going after this line
  223.  
  224.     mov   ah,0
  225.     int   16h               ;wait for a keypress
  226.     
  227.     call  RemoveInterrupt
  228.     call  TurnOffSpeaker
  229.  
  230. ByeBye:    
  231.     mov   ax,4c00h
  232.     int   21h
  233.  
  234. END START
  235.